﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataABCDModel;

public partial class Statistics : System.Web.UI.Page
{
    DataABCDEntities entiti = new DataABCDEntities();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnS1_Click(object sender, EventArgs e)
    {
        if("V"==btnS1.Text)
        {
            btnS1.Text = "/\\" ;
            cldSart.Visible = true;
        }
        else
        {
            btnS1.Text = "V";
            cldSart.Visible = false;
        }

    }
    protected void btnS2_Click(object sender, EventArgs e)
    {
        if ("V" == btnS2.Text)
        {
            btnS2.Text = "/\\";
            cldEnd.Visible = true;
        }
        else
        {
            btnS2.Text="V";
            cldEnd.Visible = false;
        }
    }
    protected void cldSart_SelectionChanged(object sender, EventArgs e)
    {
        Connect cn = new Connect();
        DateTime date = cldSart.SelectedDate;
        txtSart.Text = date.Year+"-"+date.Month+"-"+date.Day;
        btnS1.Text = "V";
        cldSart.Visible = false;
        if (ddlObjectStatistic.SelectedValue == "Revenue of Movie")
        {
            lblTime.Visible = true;
            ddlTime.Visible = true;
            DataSet dt = new DataSet();
            DataView dtv = new DataView();
            dt = cn.LoadData("tblMovieList", "SELECT * FROM tblMovieList WHERE MovieID='" + ddlMovie.SelectedValue.ToString() + "' AND DateMovie ='" + DateTime.Parse(txtSart.Text.Trim()).Date + "'");
            dtv = dt.Tables[0].DefaultView;
            ddlTime.DataSource = dtv;
            ddlTime.DataTextField = "TimeMovie";
            ddlTime.DataValueField = "TimeMovie";
            ddlTime.DataBind();
        }

    }
    protected void cldEnd_SelectionChanged(object sender, EventArgs e)
    {
        DateTime date = cldEnd.SelectedDate;
        txtEndDate.Text = date.Year + "-" + date.Month + "-" + date.Day;
        btnS2.Text = "V";
        cldEnd.Visible = false;
        if (ddlObjectStatistic.SelectedValue == "Revenue of Movie")
        {
            lblTime.Visible = false;
            ddlTime.Visible = false;
        }

    }
    protected void ddlObjectStatistic_SelectedIndexChanged(object sender, EventArgs e)
    {
        Connect cn = new Connect();
        if (ddlObjectStatistic.SelectedValue == "Revenue of Movie")
        {
            lblMovie.Visible = true;
            ddlMovie.Visible = true;
            lblTime.Visible = true;
            ddlTime.Visible = true;
            DataSet dt = new DataSet();
            DataView dtv = new DataView();
            DateTime day =new DateTime();
            day = DateTime.Now.Date;
            dt = cn.LoadData("tblMovie", "SELECT * FROM tblMovie WHERE ReleasedDay<='" + day + "' AND CloseDay >='" + day + "'");
            dtv = dt.Tables[0].DefaultView;
            ddlMovie.DataSource = dtv;
            ddlMovie.DataTextField = "MovieName";
            ddlMovie.DataValueField = "MovieID";
            ddlMovie.DataBind();
        }
        else
        {
            lblMovie.Visible = false;
            ddlMovie.Visible = false;
            lblTime.Visible = false;
            ddlTime.Visible = false;
        }
    }
    protected void ddlMovie_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        Connect cn = new Connect();
        //
        #region Feedback
        if (ddlObjectStatistic.SelectedValue == "Feedback")
        {
        if ("0000-00-00" != txtSart.Text)
        {
            if ("0000-00-00" != txtEndDate.Text)
            {
                    lblTitle4.Visible = true;
                    lblTitle4.Text = "List feed back";
                    grvShow1.Visible = true;
                    var s1 = from fd in entiti.tblFeedbacks
                             where fd.UpdateDate >= DateTime.Parse(txtSart.Text.Trim()).Date && fd.UpdateDate <= DateTime.Parse(txtEndDate.Text.Trim()).Date
                             select fd;
                    grvShow1.DataSource = s1;
                    grvShow1.DataBind();
                    lblShow1.Text = "Total feedback";
                    lblShow2.Visible = true;
                    lblShow2.Text = cn.Total(1, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblFeedback").ToString();
            }
            else
            {
                lblTitle4.Visible = true;
                lblTitle4.Text = "List feed back";
                grvShow1.Visible = true;
                var s1 = from fd in entiti.tblFeedbacks
                         where fd.UpdateDate == DateTime.Parse(txtSart.Text.Trim()).Date
                         select fd;
                grvShow1.DataSource = s1;
                lblShow1.Text = "Total feedback";
                lblShow2.Visible = true;
                lblShow2.Text = cn.Total(1, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblFeedback").ToString();
            }
        }
        else
        {
            if ("0000-00-00" != txtEndDate.Text)
            {
                lblTitle4.Visible = true;
                lblTitle4.Text = "List feed back";
                grvShow1.Visible = true;
                var s1 = from fd in entiti.tblFeedbacks
                         where fd.UpdateDate == DateTime.Parse(txtEndDate.Text.Trim()).Date
                         select fd;
                grvShow1.DataSource = s1;
                lblShow1.Text = "Total feedback";
                lblShow2.Visible = true;
                lblShow2.Text = cn.Total(1, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblFeedback").ToString();
                }
            }
        }
        #endregion
        //
        #region Revenue of Movie
        if (ddlObjectStatistic.SelectedValue == "Revenue of Movie")
        {
            if ("0000-00-00" != txtSart.Text)
           {
               if ("0000-00-00" != txtEndDate.Text)
               {
                   lblTitle4.Visible = true;
                   lblTitle4.Text = "Revenue of Movie : "+ddlMovie.Text.Trim()+"";
                   lblShow1.Visible = true;
                   lblShow1.Text = "Total of tickets sold";
                   lblShow2.Visible = true;
                   lblShow2.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "'").ToString() + "    Ticket";
                   grvShow1.Visible = true;
                   var s2 = from m1 in entiti.tblOrders
                            where m1.MovieID == ddlMovie.SelectedValue.ToString()
                            select m1;
                   grvShow1.DataSource = s2;
                   grvShow1.DataBind();
                   lblTitle5.Visible = true;
                   lblTitle5.Text = "Tickets to be paid ";
                   grvShow2.Visible = true;
                   var s3 = from o1 in entiti.tblOrders
                            where o1.MovieID == ddlMovie.SelectedValue.ToString() && o1.DateMovie >= DateTime.Parse(txtSart.Text.Trim()).Date && o1.DateMovie <= DateTime.Parse(txtEndDate.Text.Trim()).Date && o1.StatusO.ToString() == 1.ToString()
                            select o1;
                   grvShow2.DataSource = s3;
                   grvShow2.DataBind();
                   lblTitle6.Visible = true;
                   lblTitle6.Text = "Total of tickets to be paid";
                   lblShow5.Visible = true;
                   lblShow5.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString() + "    Ticket";
                   lblTitle7.Visible = true;
                   lblTitle7.Text = "Total amount of tickets";



                   lblT3.Visible = true;
                   lblS3.Visible = true;
                   lblT3.Text = "Total amount of tickets ";
                   lblS3.Text = cn.TotalM(5, 4, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString() + "    VND";
               }
               else
               {
                   lblT1.Visible = true;
                   lblS1.Visible = true;
                   hplDetail.NavigateUrl = "";
                   lblT1.Text = "Total of tickets sold";
                   lblS1.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE TimeMovie ='" + ddlTime.SelectedValue+ "' AND MovieID ='"+ddlMovie.SelectedValue.ToString()+"'").ToString()+"    Ticket";
                   lblT2.Visible = true;
                   lblS2.Visible = true;
                   lblT2.Text = "Total of tickets to be paid";
                   lblS2.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE TimeMovie ='" + ddlTime.SelectedValue + "' AND MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString() + "    Ticket";
                   lblT3.Visible = true;
                   lblS3.Visible = true;
                   lblT3.Text = "Total amount of tickets ";
                   lblS3.Text = cn.TotalM(5,4, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE TimeMovie ='" + ddlTime.SelectedValue + "' AND MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString()+"    VND";

               }
           }
            else
           {
               lblT1.Visible = true;
               lblS1.Visible = true;
               hplDetail.NavigateUrl = "";
               lblT1.Text = "Total of tickets sold";
               lblS1.Text = cn.Total(5, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "'").ToString() + "    Ticket";
               lblT2.Visible = true;
               lblS2.Visible = true;
               lblT2.Text = "Total of tickets to be paid";
               lblS2.Text = cn.Total(5, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString() + "    Ticket";
               lblT3.Visible = true;
               lblS3.Visible = true;
               lblT3.Text = "Total amount of tickets ";
               lblS3.Text = cn.TotalM(5, 4, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  MovieID ='" + ddlMovie.SelectedValue.ToString() + "' AND StatusO=1").ToString() + "    VND";
           }
        }
        #endregion
        //
        #region  Total revenue
        //if (ddlObjectStatistic.SelectedValue == "Total revenue")
        //{
        //    if ("0000-00-00" != txtSart.Text)
        //    {
        //        if ("0000-00-00" != txtEndDate.Text)
        //        {
        //            lblT1.Visible = true;
        //            lblS1.Visible = true;
        //            hplDetail.NavigateUrl = "";
        //            lblT1.Text = "Total of tickets sold";
        //            lblS1.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder ").ToString() + "    Ticket";
        //            lblT2.Visible = true;
        //            lblS2.Visible = true;
        //            lblT2.Text = "Total of tickets to be paid";
        //            lblS2.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE StatusO=1").ToString() + "     Ticket";
        //            lblT3.Visible = true;
        //            lblS3.Visible = true;
        //            lblT3.Text = "Total amount of tickets ";
        //            lblS3.Text = cn.TotalM(5, 4, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE StatusO=1").ToString() + "    VND";
        //        }
        //        else
        //        {
        //            lblT1.Visible = true;
        //            lblS1.Visible = true;
        //            hplDetail.NavigateUrl = "";
        //            lblT1.Text = "Total of tickets sold";
        //            lblS1.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder '").ToString() + "    Ticket";
        //            lblT2.Visible = true;
        //            lblS2.Visible = true;
        //            lblT2.Text = "Total of tickets to be paid";
        //            lblS2.Text = cn.Total(5, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE StatusO=1").ToString() + "    Ticket";
        //            lblT3.Visible = true;
        //            lblS3.Visible = true;
        //            lblT3.Text = "Total amount of tickets ";
        //            lblS3.Text = cn.TotalM(5, 4, DateTime.Parse(txtSart.Text.Trim()).Date, DateTime.Parse(txtSart.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  StatusO=1").ToString() + "    VND";

        //        }
        //    }
        //    else
        //    {
        //        lblT1.Visible = true;
        //        lblS1.Visible = true;
        //        hplDetail.NavigateUrl = "";
        //        lblT1.Text = "Total of tickets sold";
        //        lblS1.Text = cn.Total(5, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE ").ToString() + "    Ticket";
        //        lblT2.Visible = true;
        //        lblS2.Visible = true;
        //        lblT2.Text = "Total of tickets to be paid";
        //        lblS2.Text = cn.Total(5, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE StatusO=1").ToString() + "    Ticket";
        //        lblT3.Visible = true;
        //        lblS3.Visible = true;
        //        lblT3.Text = "Total amount of tickets ";
        //        lblS3.Text = cn.TotalM(5, 4, DateTime.Parse(txtEndDate.Text.Trim()).Date, DateTime.Parse(txtEndDate.Text.Trim()).Date, "SELECT * FROM tblOrder WHERE  StatusO=1").ToString() + "    VND";
        //    }
        //}
        #endregion
    }
}